﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Error : System.Web.UI.Page
{

    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.Title = "MaxBlox - Error Page";
        //this.Theme = Session["Theme"].ToString();
    }
    //protected override void OnError(EventArgs e)
    //{
    //    try
    //    {
    //        Exception ee = HttpContext.Current.Server.GetLastError();
    //        if (ee != null)
    //            lblErrorDescription.Text = ee.Message;
    //        else
    //            lblErrorDescription.Text = "Exception object is null.";
    //    }
    //    catch (Exception eee)
    //    {
    //        lblErrorDescription.Text = eee.Message;
    //    }
    //}
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["msg"] != null)
            lblErrorDescription.Text = Request.QueryString["msg"];
        setPageTitle();
        //Request.Params.
        //if (Request.Params["aspxerrorpath"] != null)
        //return;
        //if (Request.Params.Count>0)
        //    lblErrorURL.Text = Request.Params["aspxerrorpath"].ToString() + "<br>";
        try
        {
            if (Request.QueryString.Get("aspxerrorpath") != null)
                lblErrorURL.Text = "URL: " + Request.QueryString.Get("aspxerrorpath");

            if (Server.GetLastError() != null)
            {
                Exception ee = Server.GetLastError().GetBaseException();
                if (ee != null)
                    lblErrorDescription.Text = ee.Message;
                else
                    lblErrorDescription.Text = "Exception object is null.";
            }
        }
        catch (Exception eee)
        {
            lblErrorDescription.Text = eee.Message;
        }
        //if (IsPostBack) return;
        //lblErrorDescription.Text = "";
        //lblErrorURL.Text = "";
    }
    private void setPageTitle()
    {
        try
        {
            if (Session["pageTitle"] != null)
            {
                Page.Header.Title = Session["pageTitle"].ToString();
            }
            else
            {
                if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(".") + "\\maxbloxtitle.ini"))
                {
                    System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Current.Server.MapPath(".") + "\\maxbloxtitle.ini");
                    Session["pageTitle"] = sr.ReadLine();
                    Page.Header.Title = Session["pageTitle"].ToString();
                    sr.Close();
                    sr = null;
                }
            }
            Page.Header.Title += " - Error Page";
        }
        catch (Exception e)
        {
            LogWriter.WriteLog("Error in setPageTitle function. Error: " + e.Message);
        }
    }
}
